<script language="javascript">
	function viewTinByCat(CatID){
		window.location='?mod=news.listall&catid=' + CatID;
	}
	function viewTinByLocation(LID){
		window.location='?mod=news.listall&location=' + LID;
	}
	function viewTinByStatus(SID){
		window.location='?mod=news.listall&act=' + SID;
	}
	function viewTinByHOT(HID){
		window.location='?mod=news.listall&vip=' + HID;
	}
	function viewTinByOrder(Order){
		window.location='?mod=news.listall&order=' + Order;
	}
	function viewTinByTrangThai(TrangThai){
		window.location='?mod=news.listall&status=' + TrangThai;
	}
</script>
<?
if(isset($_GET['method']))
{
	$method = $_GET['method'];
	if($method=="del"){
		$sListId="";
		if(isset($_POST["chon"]))$sListId=$_POST["chon"];
		$sql="delete from ".$prefix."tintuc where tt_id in('".str_replace(",","','",$sListId)."')";
		mysql_query($sql);
		Redirect("Bạn đã xoá thành công","?mod=news.listall");
	}else if($method=="act"){
		$IdList=$_GET["id"];
		$act=$_GET["act"];
		if($act==1) $iact=0;else $iact=1;
		$sql="update ".$prefix."tintuc set tt_hienthi=$iact where tt_id=$IdList";
		mysql_query($sql);
		Redirect("","?mod=news.listall");		
	}else if($method=="delete"){
		$IdList=$_GET["id"];
		$sql="delete from ".$prefix."tintuc where tt_id=$IdList";
		mysql_query($sql);
		Redirect("Đã xóa thành công","?mod=news.listall");		
	}
}
$where = "";
$order ="";
if(isset($_GET['catid']))
{
	$catid = $_GET['catid'];
	if($catid != '-1'){
		$where .=" where tt_loaitintuc=$catid";
	}
}else{
	$catid = '-1';
}

if(isset($_GET['act'])){
	$act = $_GET['act'];
	if($act != 3){
		$where .= " where tt_hienthi=$act";
	}
	
}else{
	$act = 3;
}

if(isset($_GET['order'])){
	$iorder = $_GET['order'];
	$where = $where;
	if($iorder=="DESC"){
		$order .= " order by tt_ngaythang DESC";
	}else{
		$order .= " order by tt_ngaythang ASC";
	}
}else{
	$iorder = 3;
	$where = $where;
	$order .= " order by tt_ngaythang DESC";
}
	///////Paging
	$strSQL = "select * from ".$prefix."tintuc".$where.$order."";
	//echo $strSQL;
	$pp=10; 
	$parr=array();
	$parr=paging($strSQL,$pp);
	$page=$parr[0];
	$limitvalue=$parr[1];
	$numofpages=$parr[2];
	$strSQL.=" LIMIT $limitvalue, $pp";
	$rs = mysql_query($strSQL) or die('Not query');
	$i=0;
	$isexits=false;
	
	if(mysql_num_rows($rs)) $isexits=true;
?>
<div class="newsList-path"></div>
	<div style="margin-bottom:5px; font-size:14px;">
	<?
	$sql = "select count(*) as total from ".$prefix."tintuc".$where."";
	$result = mysql_query($sql) or die("Can't connect database");
	$row = mysql_fetch_array($result);
	?>
	 Có <?=$row['total']?> tin tức được tìm thấy </div>
	  <br />
	<a href="?mod=news.listall.add"><img src="images/add.png" border="0" alt="Thêm mới"/></a>&nbsp;<a href="?mod=news.listall"><img src="images/list.png" border="0" alt="Danh sách"/></a>
	<div align="right" class="newsList-search-up">
	<strong>Lọc tin </strong>&nbsp;
	<select name="FilterByCat" id="CatID" onchange="return(viewTinByCat(this.value));">
	<option value="-1" <? if($catid == '-1'){?> selected="selected" <? } ?>>--Danh mục--</option>
	<?
	$sql = "select * from ".$prefix."loaitintuc order by ltt_id ASC";
	$result = mysql_query($sql) or die("Can't connect database");
	while($row = mysql_fetch_array($result))
	{
	?>	
	<option value="<?=$row['ltt_id']?>" <? if($catid == $row['ltt_id']){?> selected="selected" <? } ?>><?=$row['ltt_ten']?></option>
	<? }?>
	  </select>
	&nbsp;<select name="FilterByStatus" id="SID" onchange="return(viewTinByStatus(this.value));">
	<option value="3" <? if($act == 3){?> selected="selected" <? } ?>>--Tình trạng--</option>
	<option value="1" <? if($act == 1){?> selected="selected" <? } ?>>Đã kích hoạt</option>
	<option value="0" <? if($act == 0){?> selected="selected" <? } ?>>Chưa kích hoạt</option>
	  </select>
	 &nbsp;<select name="FilterByOrder" id="Order" onchange="return(viewTinByOrder(this.value));">
	<option value="3" <? if($iorder == 3){?> selected="selected" <? } ?>>--Sắp xếp--</option>
	<option value="ASC" <? if($iorder == 'ASC'){?> selected="selected" <? } ?>>Mới nhất</option>
	<option value="DESC" <? if($iorder == 'DESC'){?> selected="selected" <? } ?>>Cũ nhất</option>
	  </select>
	</div>
	<form name="frmListSp" method="post" action="?mod=news.listall&method=del" onSubmit="return checkInput(this,'Bạn hãy chọn ít nhất một giá trị','Bạn chắc chắn muốn xoá không');">
	<input type="hidden" name="chon" />
	<table width="100%" border="1" bordercolor="#B2DAEE" cellpadding="4">
		<tr class="newsList-content-head">
		<td width="5%" class="newsList-content-view"><input type="checkbox" name="chkall" value="0" <? if($isexits) echo "onClick=\"docheck(this.form,0);\""?>></td>
			<td width="43%" class="newsList-content-title">Tiêu đề</td>

			<td width="9%" class="newsList-content-view"><div align="center">Hiển thị </div></td>
			<td width="22%" class="newsList-content-view"><div align="center">Loại tin tức </div></td>
			<td width="12%" class="newsList-content-position">Tùy chọn </td>
		</tr>
				<?
				while($rows = mysql_fetch_array($rs))
				{
					$i++;
					$tt_id = $rows['tt_id'];
					$tt_loaitintuc = $rows['tt_loaitintuc'];
					$tt_nguoidang = $rows['tt_nguoidang'];
					$tt_tieude = $rows['tt_tieude'];
					$tt_hinhanh = $rows['tt_anhthehien'];
					$tt_ngaythang = $rows['tt_ngaythang'];
					$tt_solanxem = $rows['tt_solanxem'];
					$tt_hienthi = $rows['tt_hienthi'];
				?>				
		<tr onmouseover="this.bgColor='#FEF2CB';" onmouseout="this.bgColor='#FFFFFF';" class="newsList-content-list" <? if($i%2==0) echo "bgcolor='#f2fff2'";?>>
			<td class="newsList-content-title"><input type="checkbox" name="Xoa" value="<?=$tt_id?>" onClick="docheckone(this.form);"></td>
			<td class="newsList-content-title">
            	<table cellpadding="0" cellspacing="0" width="100%">
                <tr>
					<td colspan="2">
						<a class="newsList-link newsList-name" href="">
						<b><?=$tt_tieude?></b></a>&nbsp;<i>(Xem:<?=$tt_solanxem?>)</i>					</td>
                <tr>
                    <td><div class="newsList-user-id" >Người đăng: <a class="newslist-normal-link" href="#"><?=$tt_nguoidang?></a></div></td>
                	<td align="right"><div class="newsList-time">Ngày đăng: <span class="newsList-date"><?=format_date($tt_ngaythang);?></span></div></td>
                </tr>
                </table>				</td>
			<td class="newsList-content-view"><div align="center"><a href="?mod=news.listall&method=act&act=<?=$tt_hienthi;?>&id=<?=$tt_id?>"><?=ImgActive($tt_hienthi);?></a></div></td>
			<td class="newsList-content-view"><div align="center"><?=tenChungLoaiTinTuc($tt_loaitintuc);?></div></td>
			<td class="newsList-content-position"><div align="center"><a href="?mod=news.listall.add&method=edit&amp;id=<?=$tt_id?>" class="menu"><img src="images/edit.gif" border="0" /></a>&nbsp; <a href="?mod=news.listall&amp;method=delete&amp;id=<?=$tt_id?>" class="menu" onclick="return confirm('Bạn có chắc chắn muốn xóa không?')"><img src="images/delete_on.gif" border="0" /></a></div></td>
		</tr>
		<? }?>
	<tr>
   <td colspan="9" align="center">
   <input type="submit" name="submit" value="   Xoá   " class="Button">
   <input type="reset" value="Làm lại" class="Button">   </td>
   </tr>
</table>
	</form>
	<div class="newsList-pagging">
	<div class="raovat-paging-bound">
	<span style="padding:5px;">
	<p align="center" class="font">
			<?php echo page_div( "?mod=news.listall&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
	</p>
	</span>
	</div>
	</div>
	<div class="newsList-button-back"><a href="javascript: history.back()">[Quay lại]</a></div>